<template>
	<view class="">
		<view class="" style="position: relative;">
			<image src="https://oss.taoding1688.com/static/uniapp/static/commission/apply_agent.png" mode="widthFix" style="width: 100%;"></image>
			<view class="title"
				style="position: absolute;top: 45%;color: #fff;left: 50rpx;font-size: 48rpx;font-weight: bold;">申请分销商
			</view>
		</view>
		<tn-form :model="form" ref="form" :errorType="['message']" :labelWidth="200" style="padding: 0 50rpx;">
			<tn-form-item :label="item.name" prop="name" v-for="(item,index) in formList" :key="index">
				<tn-input v-model="item.value" :placeholder="`请填写${item.name}`" v-if="item.type != 'image'" />
				<tn-image-upload v-if="item.type == 'image'" :header="header" :formData="formData" :action="serverUrl"
					:fileList="item.value" :maxCount="1" @on-success="onSuccess"></tn-image-upload>
			</tn-form-item>
			<!-- <tn-form-item label="身份证号" prop="intro">
				<tn-input v-model="form.intro" placeholder="请填写身份证号" />
			</tn-form-item> -->
			<!-- <tn-form-item label="身份证照片" prop="sex">
				<tn-image-upload  :header="header" :formData="formData" :action="serverUrl" :fileList="fileList" :maxCount="1" @on-success="onSuccess"></></tn-image-upload>
			</tn-form-item> -->
		</tn-form>
		<view class="" style="display: flex;font-size: 28rpx;margin: 30rpx 20rpx 20rpx 20rpx;" @click="currentShow">
			<image src="https://oss.taoding1688.com/static/uniapp/static/commission/radio.png" mode="widthFix" style="width: 35rpx;margin: 0 10rpx;"
				v-if="current==0"></image>
			<image src="https://oss.taoding1688.com/static/uniapp/static/commission/radiob.png" mode="widthFix" style="width: 35rpx;margin: 0 10rpx;"
				v-if="current==1"></image>
			<view class="" style="color: #c4c4c4;">勾选代表同意</view>
			<view class="" style="color: #e9b461;">《隐私协议》</view>
		</view>
		<view class="" style="display: flex;justify-content: center;position: fixed;bottom: 100rpx;width: 100%;">
			<tn-button backgroundColor="#e9b461" fontColor="#fff" style="width: 90%;" shape='round'
				@click="submit">提交审核</tn-button>
		</view>

	</view>
</template>

<script>
	import {
		getCommissionAgentForm,
		getCommissionAgentApply
	} from "@/apis/index.js"
	import {
		getToken
	} from "@/util/auth"
	export default {
		data() {
			return {
				current: 0,
				form: {
					name: '',
					intro: '',
					sex: ''
				},
				serverUrl: "https://www.taoding1688.com/api/common/upload",
				fileList: [],
				header: {
					'token': getToken()
				},
				formData: {
					'group': 'ugc', // 其他要传的参数
				},
				list: [],
				formList: {}
			}
		},
		mounted() {
			this.getForm()
		},
		methods: {
			submit() {
				if (!this.formList.form[0].value) {
					uni.showToast({
						title: '请输入姓名',
						icon: 'none'
					})
					return
				}
				if (!this.formList.form[1].value) {
					uni.showToast({
						title: '请输入身份证号',
						icon: 'none'
					})
					return
				}
				if (!this.formList.form[2].value) {
					uni.showToast({
						title: '请选择身份证照片',
						icon: 'none'
					})
					return
				}
				if (this.current != 1) {
					uni.showToast({
						title: '请勾选隐私协议',
						icon: 'none'
					})
					return
				}
				this.formList.form[2].value = this.formList.form[2].value.join('')

				getCommissionAgentApply(this.formList.form).then(res => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				})



			},
			getForm() {
				getCommissionAgentForm().then(res => {
					if (res.data.status == "normal") {
						this.formList = res.data.applyInfo

						this.formList[2].value = [this.formList[2].value]
					} else {
						this.formList = res.data.form
					}
				})
			},
			currentShow(e) {
				if (this.current == 1) {
					this.current = 0
				} else {
					this.current = 1
				}
			},
			onSuccess(data, index, lists, name) {
				this.formList.form[2].value = lists.map(item => {
					return item.response.data.url
				})
				// this.formList.form[2].value=res.join('')
				// this.formList.form[2].str=res
			},
		}

	}
</script>
<style lang="scss" scoped>
	.title::before {
		content: "" '';
		width: 50rpx;
		height: 10rpx;
		background: #ffffff;
		border-radius: 10rpx;
		position: absolute;
		z-index: 12;
		bottom: -20rpx;
		;
	}
</style>